package TestDemo.example.controller;

import TestDemo.example.pojo.Clazz;
import TestDemo.example.pojo.ClazzQueryParam;
import TestDemo.example.pojo.PageResult;
import TestDemo.example.pojo.Result;
import TestDemo.example.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.ArrayList;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClaszzController {
    @Autowired
    private ClazzService clazzServiceimpl;
    @GetMapping
    public Result getClazzList(ClazzQueryParam clazzQueryParam){
        log.info("获取班级列表");
        PageResult clazzParam = clazzServiceimpl.getClazzParamList(clazzQueryParam);
        return Result.success(clazzParam);
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        clazzServiceimpl.deleteById(id);
        log.info("通过{}删除班级成功",id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        clazzServiceimpl.add(clazz);
        return Result.success();
    }

    @GetMapping ("/{id}")
    public Result getById(@PathVariable("id") Integer id){
        Clazz clazz = clazzServiceimpl.getById(id);
        log.info("通过{}查询班级成功",id);
        return Result.success(clazz);
    }

    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        clazzServiceimpl.update(clazz);
        return Result.success();
    }

    @GetMapping("/list")
    public Result Clazzlist(){
        ArrayList<Clazz> clazzArrayList = clazzServiceimpl.Clazzlist();
        return Result.success(clazzArrayList);
    }
}
